package collection;

import java.util.Comparator;
import java.util.Iterator;

public class BSTDictionary<K,V> implements IDictionary<K,V> {

	private BinarySearchTree<K,V> bst;
	
	public BSTDictionary(Comparator<K> comp)
	{
		this.bst = new BinarySearchTree<K,V>(comp);
	}
	
	@Override
	public Iterator<Entry<K, V>> iterator() 
	{
		return this.bst.elementsIterator();
	}

	@Override
	public int size() 
	{
		return this.bst.size();
	}

	@Override
	public boolean isEmpty() 
	{
		return this.bst.isEmpty();
	}

	@Override
	public Entry<K, V> find(K key) 
	{
		return this.bst.findEntry(key);
	}

	@Override
	public Iterator<Entry<K, V>> findAll(K key) 
	{
		return this.bst.findAllEntries(key).elementsIterator();
	}

	@Override
	public void insert(K key, V value) 
	{
		if (this.bst.isEmpty())
		{
			this.bst.createRoot(new Entry<K,V>(key, value));
		}
		else
		{
			this.bst.insertEntry(new Entry<K,V>(key, value));
		}
	}

	@Override
	public void remove(Entry<K,V> entry) 
	{
		this.bst.removeEntry(entry);
	}

}
